<?php
namespace app\index\controller;

use think\Controller;

class Common extends Controller
{
    public function _initialize()
    {
        // 导航
        if (!$nav = cache('get_nav')) {
            $items = db('nav')->order('pid asc')->select();
            foreach ($items as $item) {
                $tmpMap[$item['id']] = $item;
            }

            foreach ($items as $item) {
                if (isset($tmpMap[$item['pid']])) {
                    $tmpMap[$item['pid']]['childrens'][] = &$tmpMap[$item['id']];
                } else {
                    $nav[] = &$tmpMap[$item['id']];
                }
            }
            cache('get_nav', $nav);
        }
        $this->assign('nav', $nav);

        // 网站设置
        if (!$website = cache('get_website')) {
            $site = db('site')->select();
            foreach ($site as $v) {
                $website[$v['name']] = $v['value'];
            }
        }
        $this->assign('website', $website);

    }
}
